"""
封装常用的业务代码模块
"""

import requests
from config import base_url,user_token

#1.主题_主题首页
def topic_home():
    data = {
        "page": 1,
        "tab": "ask",
        "limit": 10,
        "mdrender": "false"
    }
    r = requests.get(f'{base_url}/api/v1/topics', params=data)      #发送get请求，请求数据使用params参数
    return r

#2.主题_主题详情
def topic_detail(topic_id):
    data = {
        "mdrender": "True",
        "accesstoken": user_token
    }
    r = requests.get(f'{base_url}/api/v1/topic/{topic_id}', params=data)


#3.主题_新建主题
def topic_new(post_data):

    r = requests.post(f'{base_url}/api/v1/topics', data=post_data)        #post请求，请求body数据使用data参数
    return r

#4.主题_编辑主题
def topic_update(update_data):

    r = requests.post(f'{base_url}/api/v1/topics/update', data=update_data)
    return r

# 5.主题收藏_收藏主题
def topic_collect(user_token,topic_id):
    post_data = {
        "accesstoken": user_token,
        "topic_id": topic_id
    }
    r = requests.post(f'{base_url}/api/v1/topic_collect/collect', data=post_data)
    return r

#6.主题收藏_取消主题
def topic_uncollect(topic_id):
    post_data = {
        "accesstoken": user_token,
        "topic_id": topic_id
    }
    r = requests.post(f'{base_url}/api/v1/topic_collect/de_collect', data=post_data)
    return r

#7.主题_用户所收藏的主题
def topic_user_collect(user_name):
    r = requests.get(f'{base_url}/api/v1/topic_collect/{user_name}')
    return r

# 8.评论_新建评论
def topic_reply(topic_id):
    post_data = {
        "accesstoken": user_token,
        "content": "今天天气真的好"
    }
    r = requests.post(f'{base_url}/api/v1/topic/{topic_id}/replies', data=post_data)
    return r

#9. 评论_为评论点赞
def topic_ups(reply_id):
    post_data = {
        "accesstoken": user_token
    }
    r = requests.post(f'{base_url}/api/v1/reply/{reply_id}/ups', data=post_data)
    return r

#10. 用户_用户详情
def user_detail(user_name):
    r = requests.get(f'{base_url}/api/v1/user/{user_name}')
    return r

#11. 用户_验证 accessToken 的正确性
def user_accesstoken():
    post_data = {
        "accesstoken": user_token
    }
    r = requests.post(f'{base_url}/api/v1/accesstoken', data=post_data)
    return r

# 12.消息通知_获取未读消息数
def message_count():
    data = {
        "accesstoken": user_token
    }
    r = requests.get(f'{base_url}/api/v1/message/count', params=data)
    return r

#13.消息通知_获取已读和未读消息
def messages_unread_read():
    data = {
        "accesstoken": user_token,
        "mdrender": "false"
    }
    r = requests.get(f'{base_url}/api/v1/messages', params=data)
    return r

# 14.消息通知_标记全部已读
def message_mark_readed():
    post_data = {
        "accesstoken": user_token
    }
    r = requests.post(f'{base_url}/api/v1/message/mark_all', data=post_data)
    return r

#15.消息通知_标记单个消息为已读
def message_mark_one(topic_id):
    post_data = {
        "accesstoken": user_token
    }
    r = requests.post(f'{base_url}/api/v1/message/mark_one/{topic_id}', data=post_data)
    return r
